package function

import (
	_ "embed"
	"encoding/json"
	"math/rand"
	"time"
)

//go:embed title.json
var titleFile []byte

type TitleFunction struct {
	size int
	pool []string
	data []interface{}
}

func DefaultTitle(size int) *TitleFunction {
	var titles []string
	json.Unmarshal(titleFile, &titles)
	return &TitleFunction{
		size: size,
		pool: titles,
		data: make([]interface{}, 0, size),
	}
}

func (t *TitleFunction) Build() []interface{} {
	rand.Seed(time.Now().Unix())
	for i := 0; i < t.size; i++ {
		t.data = append(t.data, t.pool[rand.Intn(len(t.pool))])
	}
	return t.data
}
